package javaConcurrentDemo;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/***
 * CyclicBarrier循环栅栏 字面意思：可循环使用的屏障
 * @author Administrator
 *
 */
public class CyclicBarrierDemo {

	public static void main(String[] args) {
		 CyclicBarrier cb = new CyclicBarrier(7,()->{
			 System.out.println("****召唤神龙");
		 });
         
		 for(int i=1;i<=7;i++) {
			 final int temInt  = i;
			 new Thread(()->{
				 System.out.println(Thread.currentThread().getName()+"收集到第"+temInt+"颗龙珠");
				 try {
					cb.await();
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (BrokenBarrierException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			 },String.valueOf(i)).start();
		 }
	}

}
